﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace StormCoding.DIExtensions
{
    public static class TypeExtensions
    {
        public static bool HasAttribute<T>(this Type type) where T : Attribute
        {
            return type.IsDefined(typeof(T), inherit: true);
        }
        public static bool IsPublicNonAbstractClass(this Type type)
        {
            if (type.IsSpecialName)
            {
                return false;
            }
            if (type.IsClass && !type.IsAbstract)
            {
                if (type.HasAttribute<CompilerGeneratedAttribute>())
                {
                    return false;
                }
                return type.IsPublic || type.IsNestedPublic;
            }
            return false;
        }
    }
}
